import { defineConfig } from "vite";
import path from "path";
import react from "@vitejs/plugin-react";
import { visualizer } from 'rollup-plugin-visualizer'

// https://vitejs.dev/config/
export default defineConfig({
  base: "/story/",
  plugins: [
    react(),
    visualizer({ open: true }),
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:3000',
        ws: false,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      },
      '/fileApi': {
        target: 'http://my.zol.com.cn',
        ws: false,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/fileApi/, '')
      }
    }
  },
  build: {
    rollupOptions: {
      plugins: [],
      output: {
        compact: true,
        manualChunks: (id: string) => {
          if (id.includes("node_modules")) {
            return id.toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString()
          }
        }
      },
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          '@primary-color':"#0066ff"
        }
      }
    }
  }
});
